<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>

<%
	request.setAttribute("title", "团队详情");
	request.setAttribute("modelConfigPath", "team");
%>

<%@ include file="/WEB-INF/views/shared/master/contentHeader.jsp"%>
<style type="text/css">
.content{
margin-bottom:28px;
}
</style>

<t:panel cssClass="panel-flat form-detailed form-xs" customBody="true"
	customHead="true">
	<div class="detailed-navbar-content panel-body content">
		<t:form commandName="cooperationTeam" action="/admin/team/cooperationTeam/save"
			method="post" cssClass="form-horizontal">
			<div class="hide">
				<t:hidden path="employeeId"/>
				<input type="hidden" id="initRoleIds" value="${roleIds}" /> 
			</div>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="employeeName" cssClass="col-sm-4" />
					<t:input path="employeeName" colClass="col-sm-8" />
				</div>
				<div class="col-sm-6">
					<t:label path="employeeCode" cssClass="col-sm-4" />
					<t:input path="employeeCode" colClass="col-sm-8" cssClass="markCode" data-markCodeFor="employeeName"/>
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="employeeAccount"  cssClass="col-sm-4"  />
					<t:input path="employeeAccount" data-markCodeFor="employeeName" data-markFilter="account" colClass="col-sm-8" cssClass="markCode" />
				</div>
				<div class="col-sm-6">
					<t:label path="mobile" cssClass="col-sm-4" />
					<t:input path="mobile" colClass="col-sm-8" />
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="sex" cssClass="col-sm-4" />
					<t:selectButton path="sex" colClass="col-sm-8" />
				</div>
				<div class="col-sm-6">
					<t:label path="email" cssClass="col-sm-4" />
					<t:input path="email" colClass="col-sm-8"/>
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="createDate" cssClass="col-sm-4" />
					<t:date path="createDate" colClass="col-sm-8" readOnly="true" disabled="true"/>
				</div>
				<div class="col-sm-6">
					<t:label path="userIdentity" cssClass="col-sm-4" />
					<t:date path="userIdentity" colClass="col-sm-8" />
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-12">
					<t:label path="provinceId" cssClass="col-sm-2" />
					<t:select2 path="provinceId" colClass="col-sm-5"/>
					<t:select2 path="cityId" colClass="col-sm-5"/>
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-12">
					<t:label path="businessId" cssClass="col-sm-2" />
					<t:select2  path="businessId" colClass="col-sm-10"/>
				</div>  
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-12">
					<t:label path="roleIds" cssClass="col-sm-2" />
					<t:select2 path="roleIds"  colClass="col-sm-10" />
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-12">
					<t:label path="comments" cssClass="col-sm-2" />
					<t:textarea  path="comments" colClass="col-sm-10" />
				</div>  
			</t:formgroup>
		</t:form>
	</div>
	<div class="navbar-fixed-bottom">
	<t:panelFoot headingBtnCssClass="heading-btn pull-right-important">
		<t:button icon="icon-floppy-disk" onclick="saveData()"
			cssClass="btn-info" csize="sm">保存</t:button>
	</t:panelFoot>
	</div>
</t:panel>

<script type="text/javascript">

function saveData(){
	if (!$("form:first").valid()){
		return;
	}
	$("form:first").submit();
}

  $(function(){
	var buId=$("#businessId").val();
	var initRoleIds=$("#initRoleIds").val();
	c.log(initRoleIds);
	loadRoleSelect2(buId,initRoleIds)
	
}); 

 function loadRoleSelect2(buId,initRoleIds){
	$("#roleIds option").remove();
	if($.isNull(buId)){
		return;
	}
	var url=$.getVirtualPath()+"/admin/superbase/role/getRoleByBuId?buId="+buId;
	var roles=$.getJsonPost(url);
	if($.isNull(roles)){
		return;
	}
	var options=[];
	
	$.each(roles,function(index,role){
		var selected="";
		if(!$.isNull(initRoleIds)){
			selected=initRoleIds.indexOf(role.roleId)>=0?"selected=selected":"";	
		
		}
		
		options.push("<option "+selected+" value='"+role.roleId+"'>"+role.roleName+"</option>");
	});
	
	$("#roleIds").append(options);
 };  
 
	
	$(function(){
		 $("#provinceId").on("change",function(){
			 var provinceId=$("#provinceId").val();
			 loadProvinceSelect2(provinceId); 
		}); 
		initProvinceCity();
		
	});
 
    function initProvinceCity(){
    	var provinceId=$("#provinceId").val();
		var cityId=$("#cityId").val();
		if($.isNull(provinceId)){
			 provinceId = 'all';
			 loadProvinceSelect2(provinceId); 
		}else{
			loadProvinceSelect2(provinceId,cityId);
		}
		
    };
	
	function loadProvinceSelect2(keyId,cityId){
		
		$("#provinceId option").remove();
		$("#cityId option").remove();
		/* var pre = '';
		var suf = ''; */
		var url=$.getVirtualPath()+"/admin/team/cooperationTeam/provinceCity?keyId=all";
		var provinces =$.getJsonPost(url);
        var optProvince=[];
        
        $.each(provinces,function(index,province){
			var proSelected="";
			proSelected=province.id.indexOf(keyId)>=0?"selected=selected":"";
			/* if(province.id.indexOf(keyId)>=0){
				pre = province.paramValue;
				proSelected = "selected=selected";
			} */
			optProvince.push("<option "+proSelected+" value='"+province.id+"'>"+province.paramValue+"</option>");
	    });
        $("#provinceId").append(optProvince);
        
        
        url=$.getVirtualPath()+"/admin/team/cooperationTeam/provinceCity?keyId=" + $("#provinceId").val();
		var citys =$.getJsonPost(url);
        var optCity=[];
        
        $.each(citys,function(index,city){
			var citySelected="";
			citySelected=city.id.indexOf(cityId)>=0?"selected=selected":"";	 
			/* if(city.id.indexOf(cityId)>=0){
				suf = city.paramValue;
				citySelected = "selected=selected";
			} */
			
			optCity.push("<option "+citySelected+" value='"+city.id+"'>"+city.paramValue+"</option>");
	    });
        $("#cityId").append(optCity);

	}
</script>
<%@ include file="/WEB-INF/views/shared/base/scripts/jqueryui.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/dialog.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/contentFooter.jsp"%>
